import 'plugins/nav';
import { getParamFromSearch, getSearchFromParam, getUser, set_pagination } from 'utils';
import { get } from 'utils/request';
import 'bootstrap-paginator';

const param = getParamFromSearch();
const uid = param.uid;
const page = Number(param.page || 1);
const user = getUser() || {};
const isMe = uid == user.id; // 是否本人的简历
$('#nav').nav(isMe ? { active: '.myresumes' } : {});

get('resume/resumes' + location.search).then(d => {
  if (d.num_pages == 1 && d.page_list.length == 0) {
    $('#list').html('<h4 class="text-center">暂无简历</h4>');
  } else {
    $('#list').html(d.page_list.map(item => {
      return (`<li>
        <a href="resume-view.html?id=${item.id}">${item.title}</a>
        ${isMe ? `<a class="btn btn-default btn-xs" href="resume-edit.html?id=${item.id}">编辑</a>` : ''}
      </li>`);
    }));
    set_pagination('#pagination', d.page_number, d.num_pages);
  }
});
